<?php
/**
 * Classe para controlar o fluxo da tela Teste
 *
 * @package Controllers
 * @name TesteController
 * @author pablolopesk8
 *
 */

class TesteController extends Zend_Controller_Action
{

    /**
     * Metodo responsavel por fazer as incializacoes da tela
     *
     * @name init
     * @access public
     *
     */
    public function init()
    {
        /* Initialize action controller here */
    }

    /**
     * Action principal da classe
     *
     * @name indexAction
     * @access public
     *
     */
    public function indexAction()
    {
        // Recupera todos os registros da tabela teste e joga para a view
        $modelTeste = new Application_Model_TesteMapper();
        $this->view->registros = $modelTeste->fetchAll();
        
        $form = new Application_Form_Teste();
        $this->view->form = $form;
    }

    public function addAction()
    {
        $form = new Application_Form_Teste();
    	
    	if ($this->getRequest()->isPost()) {
    		if ($form->isValid($this->getRequest()->getPost())) {
    			$camposTeste = new Application_Model_Teste($form->getValues());
    			$mapperTeste  = new Application_Model_TesteMapper();
    			$mapperTeste->save($camposTeste);
    			
    			return $this->_helper->redirector('index');
    		}
    	}
    	
    	$this->view->form = $form;
    }
}